using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace APNotifications
{
    public class Updater
    {
        #region Properties

        private string _wsAPjunktionUrl;
        private string _ApplicationName;
        private decimal _ApplicationVersion;
        private int _Timeout;
        private NetworkCredential _nc;

        #endregion

        #region Construct

        public Updater(string wsAPjunktionUrl, string ApplicationName, decimal ApplicationVersion, int Timeout, NetworkCredential nc)
        {
            _wsAPjunktionUrl = wsAPjunktionUrl;
            _ApplicationName = ApplicationName;
            _ApplicationVersion = ApplicationVersion;
            _Timeout = Timeout;
            _nc = nc;
        }

        #endregion

        #region Public Methods

        public bool CheckForUpdate(ref string DownloadUrl)
        {
            try
            {                
                return Init().CheckIfApplicationUpdate(_ApplicationName, _ApplicationVersion, ref DownloadUrl);
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region Private Methods

        private APNotifications.wsAPjunktion.APjunktionInterface Init()
        {
            APNotifications.wsAPjunktion.APjunktionInterface _ws = new APNotifications.wsAPjunktion.APjunktionInterface();
            _ws.Url = _wsAPjunktionUrl;
            _ws.Timeout = _Timeout;
            if (_nc == null)
            { _ws.UseDefaultCredentials = true; }
            else
            { _ws.Credentials = _nc; }
            return _ws;
        }

        #endregion
    }
}
